{% extends "default.html" %}

{% block content %}
<div class="title">
	Reportes de Ventas
</div>
<div class="content">
	<div>Seleccione la venta de la que desea un reporte</div>
	<div>
		<form action="/reports/sales/" method="post">
		<table class="table_report">
			<tr>
				<th rowspan="3">Busqueda por fecha</th>
				<td>Desde</td>
				<td>D&iacute;a <select name="from_day">
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
						<option value="9">9</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
						<option value="24">24</option>
						<option value="25">25</option>
						<option value="26">26</option>
						<option value="27">27</option>
						<option value="28">28</option>
						<option value="29">29</option>
						<option value="30">30</option>
						<option value="31">31</option>
					</select>
					Mes <select name="from_month">
						<option value="1">Enero</option>
						<option value="2">Febrero</option>
						<option value="3">Marzo</option>
						<option value="4">Abril</option>
						<option value="5">Mayo</option>
						<option value="6">Junio</option>
						<option value="7">Julio</option>
						<option value="8">Agosto</option>
						<option value="9">Septiembre</option>
						<option value="10">Octubre</option>
						<option value="11">Noviembre</option>
						<option value="12">Diciembre</option>
					</select>
					A&ntilde;o <input name="from_year" maxlength="4"  value="{% now "Y" %}">
				</td>
			</tr>
			<tr>
				<td>Hasta</td>
				<td>D&iacute;a <select name="to_day">
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
						<option value="9">9</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
						<option value="24">24</option>
						<option value="25">25</option>
						<option value="26">26</option>
						<option value="27">27</option>
						<option value="28">28</option>
						<option value="29">29</option>
						<option value="30">30</option>
						<option value="31">31</option>
					</select>
					Mes <select name="to_month">
						<option value="1">Enero</option>
						<option value="2">Febrero</option>
						<option value="3">Marzo</option>
						<option value="4">Abril</option>
						<option value="5">Mayo</option>
						<option value="6">Junio</option>
						<option value="7">Julio</option>
						<option value="8">Agosto</option>
						<option value="9">Septiembre</option>
						<option value="10">Octubre</option>
						<option value="11">Noviembre</option>
						<option value="12">Diciembre</option>
					</select>
					A&ntilde;o <input name="to_year" maxlength="4" value="{% now "Y" %}">
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="hidden" name="search_method" value="1">
					<input type="submit" value="Buscar"> Fecha actual: {% now "d \de F \de Y" %}
				</td>
			</tr>
		</table>
		</form>
		<form action="/reports/sales/" method="post">
		<table class="table_report">
			<tr>
				<th rowspan="2">Por comprador</th>
				<td>
					{% if request.clients %}
						Cliente <select name="client">
						{% for c in request.clients %}
							<option value="{{ c.id }}">{{ c.user.first_name }} {{ c.user.last_name }}</option>
						{% endfor %}
						</select>
					{% else %}
						No se han registrado clientes<br>Registre sus clientes <a href="/staff/clients/">aqu&iacute;</a>
					{% endif %}
				</td>
			</tr>
			<tr>
				<td>
					<input type="hidden" name="search_method" value="2">
					<input type="submit" value="Buscar">
				</td>
			</tr>
		</table>
		</form>
		<form action="/reports/sales/" method="post">
		<table class="table_report">
			<tr>
				<th rowspan="2">Por vendedor</th>
				<td>
					{% if request.vendors %}
						Vendedor <select name="vendor">
						{% for v in request.vendors %}
							<option value="{{ v.id }}">{{ v.user.first_name }} {{ v.user.last_name }} [{{ v.user.username }}] </option>
						{% endfor %}
						</select>
					{% else %}
						No se han registrado vendedores<br>Registre sus vendedores <a href="/staff/vendors/">aqu&iacute;</a>
					{% endif %}
				</td>
			</tr>
			<tr>
				<td>
					<input type="hidden" name="search_method" value="3">
					<input type="submit" value="Buscar">
				</td>
			</tr>
		</table>
		</form>
	</div>
	<div>
		<b>{{ request.message }}</b><br>Ventas encontradas		
		<table class="table_report">
			<tr>
				<th>C&oacute;digo de venta</th>
				<th>Fecha</th>
				<th>Cliente</th>
				<th>Vendedor</th>
				<th>Nro Factura</th>
				<th>Acci&oacute;n</th>
			</tr>
			{% if request.sales %}
				{% for s in request.sales %}
					<tr>
						<td>{{ s.id }}</td>
						<td>{{ s.made }}</td>
						<td>{{ s.client.user.first_name }} {{ s.client.user.last_name }}</td>
						<td>{{ s.vendor.user.first_name }} {{ s.vendor.user.last_name }}</td>
						<td>{{ s.bill_number }}</td>
						<td><a href="javascript:show_sale({{ s.id }})">Ver Reporte</a></td>
					</tr>
				{% endfor %}
			{% else %}
			<tr>
				<td colspan="6">No se han encontrado ventas</td>
			</tr>
			{% endif %}
		</table>
	</div>
</div>
{% endblock %}